import type { ComponentMeta } from '@/definitions/type'
import { type MaybeRefOrGetter, toValue } from 'vue'

export enum SpaceOption {
  default = 0,
  custom = 1,
}
export const spaceOptions: Option<SpaceOption>[] = [
  { value: SpaceOption.default, label: '默认' },
  { value: SpaceOption.custom, label: '自定义' },
]
interface SpaceSetting {
  paddingTop: number
  paddingRight: number
  paddingBottom: number
  paddingLeft: number
}
export function getInitialSpaceMobile(activeRenderRefOrGetter: MaybeRefOrGetter<ComponentMeta<SpaceSetting>>) {
  const activeRender = toValue(activeRenderRefOrGetter)
  if (activeRender) {
    const { paddingTop, paddingRight, paddingBottom, paddingLeft } = activeRender.config
    return [paddingTop, paddingRight, paddingBottom, paddingLeft].some(Boolean) ? SpaceOption.custom : SpaceOption.default
  }
  return SpaceOption.default
}
interface SpaceSettingPC {
  paddingTopPC: number
  paddingRightPC: number
  paddingBottomPC: number
  paddingLeftPC: number
}
export function getInitialSpacePC(activeRenderRefOrGetter: MaybeRefOrGetter<ComponentMeta<SpaceSettingPC>>) {
  const activeRender = toValue(activeRenderRefOrGetter)
  if (activeRender) {
    const { paddingTopPC, paddingRightPC, paddingBottomPC, paddingLeftPC } = activeRender.config
    return [paddingTopPC, paddingRightPC, paddingBottomPC, paddingLeftPC].some(Boolean) ? SpaceOption.custom : SpaceOption.default
  }
  return SpaceOption.default
}
